package com.jp.fm.data;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang3.builder.ToStringBuilder;

public class Transaction implements Comparable<Transaction> {

	private Date date = null;
	private Integer id = null;
	private String account = null;
	private Float amount = null;
	private Category category = null;
	private String externalId = null;
	private String description = null;
	private boolean confirmed = false;
	private Integer parentId = null;
	private String note = null;
	private List<Transaction> compositeTransactions = new ArrayList<Transaction>();

	public Transaction(final Date date, final Integer id, final String account,
			final Float amount, final Category category,
			final String externalId, final String description,
			final boolean confirmed, final Integer parentId) {
		super();
		this.date = date;
		this.id = id;
		this.account = account;
		this.amount = amount;
		this.category = category;
		this.externalId = externalId;
		this.description = description;
		this.confirmed = confirmed;
		this.parentId = parentId;
	}

	@Override
	public final int compareTo(final Transaction o) {

		return this.getDate().compareTo(o.getDate());
	}

	@Override
	public final boolean equals(final Object arg0) {

		if (arg0 instanceof Transaction) {
			return this.id.equals(((Transaction) arg0).getId());
		}
		return false;
	}

	@Override
	public final int hashCode() {
		return super.hashCode();
	}

	public static class DescendingComparator implements Comparator<Transaction> {

		@Override
		public final int compare(final Transaction o1, final Transaction o2) {

			return o2.getDate().compareTo(o1.getDate());
		}

	}

	public final String getNote() {
		return this.note;
	}

	public final void setNote(final String note) {
		this.note = note;
	}

	public final List<Transaction> getCompositeTransactions() {
		return this.compositeTransactions;
	}

	public final void setCompositeTransactions(
			final List<Transaction> compositeTransactions) {

		this.compositeTransactions = compositeTransactions;
	}

	public final boolean isConfirmed() {
		return confirmed;
	}

	public final void setConfirmed(final boolean confirmed) {
		this.confirmed = confirmed;
	}

	public final Date getDate() {
		return this.date;
	}

	public final void setDate(final Timestamp date) {
		this.date = date;
	}

	public final Integer getId() {
		return this.id;
	}

	public final void setId(final Integer id) {
		this.id = id;
	}

	public final String getAccount() {
		return this.account;
	}

	public final void setAccount(final String account) {
		this.account = account;
	}

	public final Float getAmount() {
		return this.amount;
	}

	public final void setAmount(final Float amount) {
		this.amount = amount;
	}

	public final Category getCategory() {
		return this.category;
	}

	public final void setCategory(final Category category) {
		this.category = category;
	}

	public final String getExternalId() {
		return this.externalId;
	}

	public final void setExternalId(final String externalId) {
		this.externalId = externalId;
	}

	public final String getDescription() {
		return this.description;
	}

	public final void setDescription(final String description) {
		this.description = description;
	}

	public final Integer getParentId() {
		return this.parentId;
	}

	public final String toString() {
		return ToStringBuilder.reflectionToString(this).toString();
	}
}
